package com.sc.admin.common.result;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 分页响应结构体
 *
 * @author shen chen
 * @since 2022/2/18 23:29
 */
@Data
public class PageResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 2625797397354016798L;
    private String code;
    private Data<T> data;
    private String msg;

    public static <T> PageResult<T> success(IPage<T> page) {
        PageResult<T> result = new PageResult<>();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());

        Data<T> data = new Data<T>();
        data.setList(page.getRecords());
        data.setTotal(page.getTotal());

        result.setData(data);
        result.setMsg(ResultCodeEnum.SUCCESS.getMsg());
        return result;
    }

    @lombok.Data
    public static class Data<T> {


        private List<T> list;

        private long total;

    }
}
